/**
 * @param {number} x
 * @return {boolean}
 */

Array.prototype.sameStructureAs = function (other) { return JSON.stringify(this).replace(/\d/g, "") == JSON.stringify(other).replace(/\d/g, "") ? true : false };

Array.prototype.sameStructureAs = function (other) {
  return (this.length === other.length) ? this.every(function (el, i) {
    return Array.isArray(el) ? el.sameStructureAs(other[i]) : true;
  }) : false;
};


Array.prototype.sameStructureAs = function (other) {
  if (!Array.isArray(other) || this.length != other.length)
    return false;

  for (var i = 0; i < this.length; ++i) {
    if (Array.isArray(this[i])) {
      if (!this[i].sameStructureAs(other[i])) {
        return false;
      }
    } else if (Array.isArray(other[i])) {
      return false;
    }
  }
  return true;
};


Array.prototype.sameStructureAs = function (other) {
  return isArray(other) && this.length == other.length && this.every(function (a, i) {
    var b = other[i];
    return isArray(a) ? a.sameStructureAs(b) : isArray(a) == isArray(b);
  });
};

Array.prototype.sameStructureAs = function (other) {
  return this.length == other.length && this.every((x, i) => isArray(x) == isArray(other[i]) && (!isArray(x) || x.sameStructureAs(other[i])));
};


Array.prototype.sameStructureAs = function (o) {
  return isArray(o) && JSON.stringify(this).replace(/"(\[|\])"/g, "x").replace(/[^\[,'\]]/g, "") === JSON.stringify(o).replace(/"(\[|\])"/g, "x").replace(/[^\[,'\]]/g, "")
};



console.log([1, 1, 1].sameStructureAs([2, 2, 2]));
console.log([1, [1, 1]].sameStructureAs([2, [2, 2]]));
console.log([[[], []]].sameStructureAs([[[], []]]));

console.log([1, [1, 1]].sameStructureAs([[2, 2], 2]));
console.log([1, [1, 1]].sameStructureAs([[2], 2]));
console.log([[[], []]].sameStructureAs([[1, 1]]));

console.log([1, '[', ']'].sameStructureAs(['[', ']', 1]));
